<template>
  <div class="countyFirst" v-loading="listLoading">
    <el-form :inline="true" label-width="90px">
      <div class="maintitle">竣工初验基本信息</div>
      <div class="formcontent">
        <div class="basicInformation">
          <span>项目名称：{{projCheckData.projectName == null ? '暂无项目名称' : projCheckData.projectName}}</span>
          <span>红线面积：{{projCheckData.redLine == null ? '0' : projCheckData.redLine}}公顷</span>
          <span>实施规模：{{projCheckData.implementScale == null ? '0' : projCheckData.implementScale}}公顷</span>
          <span>新增耕地面积：{{projCheckData.newPlow == null ? '0' : projCheckData.newPlow}}公顷</span>
          <span>投资规模：{{projCheckData.investmentScale == null ? '0' : projCheckData.investmentScale}}万元</span>
        </div>
        <el-form-item label="验收专家组长" label-width="98px">
          <el-input :disabled="disabled" v-model="checkData.acceptorLeader" style="width:200px;"></el-input>
        </el-form-item>
        <el-form-item label="验收专家成员" label-width="98px">
          <el-input :disabled="disabled" v-model="checkData.acceptorMember" style="width:200px;"></el-input>
        </el-form-item>
        <div>
          <el-form-item label="验收人员" label-width="98px">
            <el-input :disabled="disabled" v-model="checkData.acceptor" style="width:513px;"></el-input>
          </el-form-item>
        </div>
        <div>
          <el-form-item label="验收日期" label-width="98px">
            <el-date-picker
              :disabled="disabled"
              v-model="time.startTime"
              value-format="yyyy-MM-dd"
              @change="changTime"
              placeholder="选择日期"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="至" label-width="26px">
            <el-date-picker
              :disabled="disabled"
              v-model="time.endTime"
              value-format="yyyy-MM-dd"
              @change="changTime"
              placeholder="选择日期"
            ></el-date-picker>
          </el-form-item>
        </div>
        <el-form-item label="验收结论" label-width="98px">
          <el-radio-group :disabled="disabled" v-model="checkData.ending">
            <el-radio label="0">通过</el-radio>
            <el-radio label="1">不通过</el-radio>
          </el-radio-group>
        </el-form-item>
      </div>
      <div class="maintitle">附件信息</div>
      <el-form-item label="（初验）验收意见" label-width="125px" style="margin-top:20px;">
        <el-upload
          v-if="!disabled"
          accept=".pdf"
          :disabled="disabled"
          :action="uploadUrl"
          :file-list="fileList[0]"
          :on-success="getreport"
        >
          <el-button v-if="!disabled" size="small" type="primary">上传</el-button>
          <!-- <el-button @click="seePdf(0)" v-if="disabled" size="small" type="primary">查看</el-button> -->
        </el-upload>
        <seeFujianForList v-if="disabled && fileList[0]" @openPdf="seePdf" :file-obj="fileList[0]" :file-num="0" />
      </el-form-item>
      <div class="btn">
        <el-button v-if="!disabled" type="primary" @click="addCheckInfo">提交</el-button>
        <el-button @click="back">返回</el-button>
      </div>
    </el-form>
    <el-dialog :close-on-click-modal="false" :title="pdfName" :visible.sync="pdfFlag" width="50%">
      <div class="pdfBox">
        <iframe :src="$https + pdfUrl" style="width:100%;height:600px;" frameborder="0"></iframe>
      </div>
    </el-dialog>
  </div>
</template>



<script>
//引入requst
import {
  getCheckInfoF,
  addCheckInfoF,
  getFile
} from "@/api/completionAcceptance/acceptance";
//引入公共方法
import { formatDateTime } from "@/utils/index";
import config from "@/config/index.js";
import seeFujianForList from "@/components/seeFujianForList";
export default {
  components: {
    seeFujianForList
  },
  data() {
    return {
      uploadUrl: config.uploadUrl, //上传接口
      name1: null,
      name2: null,
      name3: null,
      value: null,
      value1: null,
      radio: "1",
      //项目相关数据结构
      projCheckData: {
        projectName: null,
        redLine: null, //红线面积
        implementScale: null, //实施规模
        newPlow: null, //新增耕地面积
        investmentScale: null //投资规模
      },
      //验收相关数据结构
      // flag:null,//0:暂存;1:提交
      checkData: {
        projectId: localStorage.getItem("projectId"), //项目id
        acceptor: null, //验收人员
        acceptorLeader: null, //验收专家组长
        acceptorMember: null, //验收专家成员
        annexId: null, //附件id
        beginTime: null, //初验日期开始
        endTime: null, //初验日期结束
        ending: "0" //验收结论：0：通过。1：不通过
      },
      //验收日期
      time: {
        startTime: null,
        endTime: null
      },
      disabled: true,
      projectId: localStorage.getItem("projectId") || "",
      listLoading: false, //加载效果
      fileList: [],
      pdfUrl: "",
      pdfFlag: false,
      pdfName: ""
    };
  },
  //初始化数据
  created() {},
  mounted() {
    if (this.$route.name === localStorage.getItem("key")) {
      this.disabled = false;
    }
    if (localStorage.getItem("lookStatus") == 2) {
      this.disabled = true;
    }
    this.getCheckInfo();
  },
  methods: {
    back() {
      this.$router.push("/projectManagement/projectImplementation/dealwith");
    },
    //查看当前PDF
    seePdf(num) {
      this.pdfFlag = true;
      this.pdfUrl = this.fileList[num][0].url;
      this.pdfName = this.fileList[num][0].name;
    },
    //获取验收信息
    getCheckInfo() {
      this.listLoading = true;
      let data = {
        projectId: this.projectId
      };
      getCheckInfoF(data)
        .then(res => {
          if (res.code == 1000 && res.data) {
            console.log(res.data, "我dnmd");
            //成功
            this.listLoading = false;
            this.projCheckData = res.data.projectInvestmentDTO; //赋值项目基本数据
            if (res.data.completionAcceptanceInfoDTO) {
              this.checkData = res.data.completionAcceptanceInfoDTO || {}; //赋值验收人员基本数据
              console.log(
                res.data.completionAcceptanceInfoDTO.annexId,
                "附件ID"
              );
              var data1 = {
                fileId: res.data.completionAcceptanceInfoDTO.annexId
              };
              getFile(data1).then(res1 => {
                console.log(res1, "文件信息");
                this.fileList = [
                  [{ name: res1.data.fileName, url: res1.data.filePath }]
                ];
              });
              //赋值时间戳
              if (res.data.completionAcceptanceInfoDTO.beginTime !== null) {
                //开始时间
                this.time.startTime = res.data.completionAcceptanceInfoDTO.beginTime.slice(
                  0,
                  10
                ); //转换时间戳
              }
              if (res.data.completionAcceptanceInfoDTO.endTime !== null) {
                this.time.endTime = res.data.completionAcceptanceInfoDTO.endTime.slice(
                  0,
                  10
                ); //转换时间戳
              }
            }
          }
        })
        .catch(err => {
          this.listLoading = false;
          console.log("报错", err);
        });
    },
    //添加验收信息
    addCheckInfo() {
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
      let data = {};
      //循环验证是否为空
      for (let i in this.checkData) {
        if (this.checkData[i] == null) {
          delete this.checkData[i];
        }
      }
      data = this.checkData;
      data.flag = 1; //提交
      addCheckInfoF(data)
        .then(res => {
          loading.close();
          this.$message({
            message: "提交成功",
            type: "success"
          });
          this.getCheckInfo();
          this.$router.push(
            "/projectManagement/projectImplementation/dealwith"
          );
        })
        .catch(err => {
          loading.close();
        });
    },
    //上传文件
    getreport(response, file, fileList) {
      //赋值附件id
      this.checkData.annexId = response.data.id;
    },
    changTime() {
      if (this.time.startTime !== null) {
        this.checkData.beginTime = this.time.startTime + " " + "00:00:00"; //2019-11-12 2:00:9转换格式
      } else {
        this.checkData.beginTime = null; //初始化数据
      }
      if (this.time.endTime !== null) {
        this.checkData.endTime = this.time.endTime + " " + "00:00:00"; //2019-11-12 2:00:9转换格式
      } else {
        this.checkData.endTime = null; //初始化数据
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.countyFirst {
  padding: 20px 20px 0 20px;
  min-height: calc(100vh - 154px);
  background-color: #fff;
  .maintitle {
    font-size: 18px;
    font-family: PingFang SC;
    font-weight: bold;
    line-height: 25px;
    color: #4d4d4d;
  }
  .formcontent {
    margin-top: 30px;
    .basicInformation {
      font-size: 14px;
      font-family: PingFang SC;
      font-weight: 500;
      line-height: 20px;
      color: #8c8c8c;
      margin-bottom: 20px;
      span {
        margin-right: 60px;
      }
    }
  }
}
</style>
<style lang="scss" scoped>
/deep/ .el-form--inline .el-form-item__label {
  color: #a1a1a1;
}

.btn {
  margin-top: 30px;
}
</style>